Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promotions: Deprecate Spree::PromotionRule#actionable and split rules that implement it #4321

Closed
wants to merge 18 commits into from

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Mar 30, 2022

The API of promotion rules is a bit strange: There's the applicable method, which looks like promotion rules could apply to line items as well as orders, and there's actionable?, which is like eligible?, but for line items.

The Product rule is really two rules in one: An order rule (Does this order contain product x?) and a line item rule (Is this line item product x?).

Same with the Taxon rule:

  • Does the order contain a product with taxon x?
  • Does the line item have a product with taxon x?

Same with the OptionValue rule:

  • Does the order contain a variant with option value X?
  • Does the line item have a variant with option value X?

What this PR does is

  • split those rules up into two
  • migrate people's promotions that use these rules such that they now have the additional "line item" rule as well, preserving behavior in existing stores
  • deprecate Spree::Promotion#line_item_actionable?
  • deprecate Spree::PromotionRule#actionable?

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I've changed the guides to reflect my changes

Copy link
Member

@jarednorman jarednorman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, though we could additionally deprecate the old rule if we want, right?

@mamhoff mamhoff marked this pull request as draft March 31, 2022 15:41
@mamhoff
Copy link
Contributor Author

mamhoff commented Mar 31, 2022

I've found a bug in the promotion system that makes line-item level rules do things we don't want them to do, so I'm marking this as draft until I've got the fix for that into a state that works. I'm likely also going to split the other two rules that have actionable? and deprecate that and related methods. There is a little bit of UI work left that should help admins understand the new system a lot better, as well.

In this PR, I'm moving the Product rule to an OrderProduct rule, but given that this is an STI class, and deprecating classes requires changes to the type column, I think I'm rather going to build an upgrade path that simply adds the line items rules to any promotions that have rules with actionable?.

@mamhoff mamhoff force-pushed the line-item-product-rule branch 3 times, most recently from b3d19a8 to 025581a Compare April 1, 2022 11:38
@mamhoff mamhoff marked this pull request as ready for review April 1, 2022 11:53
@mamhoff
Copy link
Contributor Author

mamhoff commented Apr 1, 2022

Hm, this got a bit bigger, but I think I got to a good place with this. I'm not deprecating the old rules; instead I leave them to do what their names and documentation and implementation say that they do: Check order eligibility. I added new rules for line item eligibility, and deprecated the use of actionable? for line items.

This change gives meaning to the applicable? method, and it allows to extend the promotion system to also support checks for e.g. shipments or shipping rates in the future.

@mamhoff mamhoff requested a review from jarednorman April 1, 2022 11:55
@mamhoff
Copy link
Contributor Author

mamhoff commented Apr 1, 2022

@jarednorman I've re-requested your review because this now contains a bunch more change than what you initially reviewed.

@mamhoff mamhoff changed the title Promotions: Split Product Rule into Two Promotions: Deprecate Spree::PromotionRule#actionable and split rules that implement it Apr 1, 2022
@mamhoff mamhoff force-pushed the line-item-product-rule branch from c2dd392 to b17739d Compare April 1, 2022 12:01
@mamhoff mamhoff mentioned this pull request Apr 4, 2022
5 tasks
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work. Thank you for removing some of the confusing parts of the promotion system.

core/app/models/spree/promotion/rules/line_item_product.rb Outdated Show resolved Hide resolved
core/config/locales/en.yml Show resolved Hide resolved
core/app/models/spree/promotion/rules/line_item_taxon.rb Outdated Show resolved Hide resolved
core/app/models/spree/promotion/rules/option_value.rb Outdated Show resolved Hide resolved
core/app/models/spree/promotion.rb Show resolved Hide resolved
core/app/models/spree/promotion.rb Show resolved Hide resolved
mamhoff added 16 commits April 19, 2022 11:27
This rule is like "Product", but only applies to line items.
This rule is now only applicable to an order, and the naming should
reflect that.
This spec allows me to show some of the weird things in the promotion
system.
When we have a promotion with a line item rule that evaluates to
ineligible for a line item, it will still call "actionable?" on that
rule, which will evaluate to `true`, and create an adjustment on line
items that will always be ineligible.
There was only one option for the match policy, so we can get rid of it.
This promotion rule shall replace the use of `actionable` on the
`OptionValue` promotion rule.
This Rule can replace the use of `actionable?` on the taxon promotion
rule.
Now that the Order, Taxon, and OptionValue rules only operate on orders,
we need to add the respective line item rules to the promotions that
need them.
This can now be accomplished using the LineItemActionable rule.
This can be done with the LineItemTaxon rule now.
This method now runs through promotion.eligible, which checks for the
presence of actions.
We now have a few more promotion rules.
@mamhoff mamhoff force-pushed the line-item-product-rule branch from b17739d to 2250f78 Compare April 19, 2022 09:35
@mamhoff mamhoff force-pushed the line-item-product-rule branch from 2250f78 to 2f5e451 Compare April 19, 2022 12:26
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing

@mamhoff
Copy link
Contributor Author

mamhoff commented May 9, 2022

@kennyadsl would you mind having a look? Would this also be a change for 4.0?

@kennyadsl
Copy link
Member

kennyadsl commented Jun 7, 2022

@mamhoff nope, if the public methods are deprecated and there's a clear transition path for who needs to change something in their codebase, I think we can marge this before 4.0 and only remove the deprecated parts in that major.

Still, I didn't have time to review this PR yet, it's a bit large and requires some effort. Do you think there's a way or makes sense to split this into smaller PRs?

@mamhoff
Copy link
Contributor Author

mamhoff commented Jun 7, 2022

@kennyadsl I don't think I can meaningfully split it into smaller pull requests. I'm depecrating an API here, and I'm providing a replacement. I'm also implementing this change across the promotion rules we have. This will necessarily take a few LOC, but splitting it up over multiple PRs I think would hurt readability and understandability of what's going on. Sorry! But do take your time. Best!

@kennyadsl
Copy link
Member

Update: I had a quick look and this looks very good. I also asked some team members to check if this would impact the stores they are working on. I will approve once I have positive answers. In the meantime, thanks for the fantastic work, Martin!

@mamhoff
Copy link
Contributor Author

mamhoff commented Jul 20, 2022

I think I do need to add more stuff from #4296 to this PR. Notably this will introduce bugs when re-calculating adjustments.

@mamhoff mamhoff marked this pull request as draft July 20, 2022 11:56
@kennyadsl kennyadsl added the type:enhancement Proposed or newly added feature label Aug 23, 2022
@waiting-for-dev waiting-for-dev added changelog:solidus_core Changes to the solidus_core gem changelog:solidus_backend Changes to the solidus_backend gem labels Aug 30, 2022
@mamhoff
Copy link
Contributor Author

mamhoff commented Nov 3, 2023

@mamhoff mamhoff closed this Nov 3, 2023
@mamhoff mamhoff deleted the line-item-product-rule branch November 3, 2023 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_core Changes to the solidus_core gem type:enhancement Proposed or newly added feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants